from flask import Blueprint,jsonify,request
from db import db1
from utils.rs import rs
import json
import datetime
import time
from utils.myfile import get_data,post_data

bp_client = Blueprint('client',__name__)


@bp_client.route('/getcompany')
def getcompany():
    sql = "select * from customer_manager"
    res = db1.find_all(sql)
    # db1.commit()
    return jsonify({'code':200,'list':res})


@bp_client.route('/getrefrom')
def getrefrom():
    sql = "select * from reg_form"
    res = db1.find_all(sql)
    return jsonify({'code':200,'list':res})

@bp_client.route('/addcustomer',methods=['POST','GET'])
def addcustomer():
    if request.method == 'POST':
        data = post_data()
        now = int(time.time())
        sql = "insert into customer(name,company_name,manager_id,refromid,addtime) values('%s','%s',%d,%d,'%s')"%(data['name'],data['company_name'],int(data['manager_id']),int(data['refromid']),now)
        db1.add(sql)
        db1.commit()
        return jsonify({'code': 200, 'msg': '添加成功'})